home *** CD-ROM | disk | FTP | other *** search
/ Cre@te Online 2000 December / Cre@teOnline CD05.iso / MacSoft / XML ConsoleMax.sea / XML ConsoleMax / Required / swingall.jar / javax / swing / text / html / HTMLDocument$HTMLReader.class (.txt) < prev    next >
Encoding:
Java Class File  |  1999-07-15  |  18.2 KB  |  707 lines

  1. package javax.swing.text.html;
  2.  
  3. import java.net.MalformedURLException;
  4. import java.net.URL;
  5. import java.util.Hashtable;
  6. import java.util.Stack;
  7. import java.util.Vector;
  8. import javax.swing.event.UndoableEditEvent;
  9. import javax.swing.event.DocumentEvent.EventType;
  10. import javax.swing.text.AbstractDocument;
  11. import javax.swing.text.AttributeSet;
  12. import javax.swing.text.BadLocationException;
  13. import javax.swing.text.DefaultStyledDocument;
  14. import javax.swing.text.Element;
  15. import javax.swing.text.MutableAttributeSet;
  16. import javax.swing.text.SimpleAttributeSet;
  17. import javax.swing.text.StyleConstants;
  18. import javax.swing.text.html.HTML.Attribute;
  19. import javax.swing.text.html.HTML.Tag;
  20. import javax.swing.undo.CompoundEdit;
  21.  
  22. public class HTMLDocument$HTMLReader extends HTMLEditorKit.ParserCallback {
  23.    // $FF: synthetic field
  24.    private final HTMLDocument this$0;
  25.    int threshold;
  26.    int offset;
  27.    boolean inParagraph;
  28.    boolean impliedP;
  29.    boolean inPre;
  30.    boolean inTextArea;
  31.    TextAreaDocument textAreaDocument;
  32.    boolean inTitle;
  33.    boolean lastWasNewline;
  34.    boolean emptyAnchor;
  35.    boolean midInsert;
  36.    boolean inBody;
  37.    HTML.Tag insertTag;
  38.    boolean insertInsertTag;
  39.    boolean foundInsertTag;
  40.    int popDepth;
  41.    int pushDepth;
  42.    Map lastMap;
  43.    boolean inStyle;
  44.    String defaultStyle;
  45.    Vector styles;
  46.    boolean inHead;
  47.    boolean isStyleCSS;
  48.    boolean emptyDocument;
  49.    AttributeSet styleAttributes;
  50.    Option option;
  51.    protected Vector parseBuffer;
  52.    protected MutableAttributeSet charAttr;
  53.    Stack charAttrStack;
  54.    Hashtable tagMap;
  55.    int inBlock;
  56.  
  57.    public HTMLDocument$HTMLReader(HTMLDocument var1, int var2) {
  58.       this(var1, var2, 0, 0, (HTML.Tag)null);
  59.    }
  60.  
  61.    public HTMLDocument$HTMLReader(HTMLDocument var1, int var2, int var3, int var4, HTML.Tag var5) {
  62.       this(var1, var2, var3, var4, var5, true);
  63.    }
  64.  
  65.    HTMLDocument$HTMLReader(HTMLDocument var1, int var2, int var3, int var4, HTML.Tag var5, boolean var6) {
  66.       this.this$0 = var1;
  67.       this.inParagraph = false;
  68.       this.impliedP = false;
  69.       this.inPre = false;
  70.       this.inTextArea = false;
  71.       this.textAreaDocument = null;
  72.       this.inTitle = false;
  73.       this.lastWasNewline = true;
  74.       this.inStyle = false;
  75.       this.inHead = false;
  76.       this.parseBuffer = new Vector();
  77.       this.charAttr = new SimpleAttributeSet();
  78.       this.charAttrStack = new Stack();
  79.       this.inBlock = 0;
  80.       this.emptyDocument = ((AbstractDocument)var1).getLength() == 0;
  81.       this.isStyleCSS = "text/css".equals(var1.getDefaultStyleSheetType());
  82.       this.offset = var2;
  83.       this.threshold = var1.getTokenThreshold();
  84.       this.tagMap = new Hashtable(57);
  85.       new HTMLDocument.HTMLReader.TagAction(this);
  86.       HTMLDocument.HTMLReader.BlockAction var8 = new HTMLDocument.HTMLReader.BlockAction(this);
  87.       HTMLDocument.HTMLReader.ParagraphAction var9 = new HTMLDocument.HTMLReader.ParagraphAction(this);
  88.       HTMLDocument.HTMLReader.CharacterAction var10 = new HTMLDocument.HTMLReader.CharacterAction(this);
  89.       HTMLDocument.HTMLReader.SpecialAction var11 = new HTMLDocument.HTMLReader.SpecialAction(this);
  90.       HTMLDocument.HTMLReader.FormAction var12 = new HTMLDocument.HTMLReader.FormAction(this);
  91.       HTMLDocument.HTMLReader.HiddenAction var13 = new HTMLDocument.HTMLReader.HiddenAction(this);
  92.       HTMLDocument.HTMLReader.ConvertAction var14 = new HTMLDocument.HTMLReader.ConvertAction(this);
  93.       this.tagMap.put(Tag.A, new HTMLDocument.HTMLReader.AnchorAction(this));
  94.       this.tagMap.put(Tag.ADDRESS, var10);
  95.       this.tagMap.put(Tag.APPLET, var13);
  96.       this.tagMap.put(Tag.AREA, new HTMLDocument.HTMLReader.AreaAction(this));
  97.       this.tagMap.put(Tag.B, var14);
  98.       this.tagMap.put(Tag.BASE, new HTMLDocument.HTMLReader.BaseAction(this));
  99.       this.tagMap.put(Tag.BASEFONT, var10);
  100.       this.tagMap.put(Tag.BIG, var10);
  101.       this.tagMap.put(Tag.BLOCKQUOTE, var8);
  102.       this.tagMap.put(Tag.BODY, var8);
  103.       this.tagMap.put(Tag.BR, var11);
  104.       this.tagMap.put(Tag.CAPTION, var8);
  105.       this.tagMap.put(Tag.CENTER, var8);
  106.       this.tagMap.put(Tag.CITE, var10);
  107.       this.tagMap.put(Tag.CODE, var10);
  108.       this.tagMap.put(Tag.DD, var8);
  109.       this.tagMap.put(Tag.DFN, var10);
  110.       this.tagMap.put(Tag.DIR, var8);
  111.       this.tagMap.put(Tag.DIV, var8);
  112.       this.tagMap.put(Tag.DL, var8);
  113.       this.tagMap.put(Tag.DT, var9);
  114.       this.tagMap.put(Tag.EM, var10);
  115.       this.tagMap.put(Tag.FONT, var14);
  116.       this.tagMap.put(Tag.FORM, var10);
  117.       this.tagMap.put(Tag.FRAME, var11);
  118.       this.tagMap.put(Tag.FRAMESET, var8);
  119.       this.tagMap.put(Tag.H1, var9);
  120.       this.tagMap.put(Tag.H2, var9);
  121.       this.tagMap.put(Tag.H3, var9);
  122.       this.tagMap.put(Tag.H4, var9);
  123.       this.tagMap.put(Tag.H5, var9);
  124.       this.tagMap.put(Tag.H6, var9);
  125.       this.tagMap.put(Tag.HEAD, new HTMLDocument.HTMLReader.HeadAction(this));
  126.       this.tagMap.put(Tag.HR, var11);
  127.       this.tagMap.put(Tag.HTML, var8);
  128.       this.tagMap.put(Tag.I, var14);
  129.       this.tagMap.put(Tag.IMG, var11);
  130.       this.tagMap.put(Tag.INPUT, var12);
  131.       this.tagMap.put(Tag.ISINDEX, new HTMLDocument.HTMLReader.IsindexAction(this));
  132.       this.tagMap.put(Tag.KBD, var10);
  133.       this.tagMap.put(Tag.LI, var8);
  134.       this.tagMap.put(Tag.LINK, new HTMLDocument.HTMLReader.LinkAction(this));
  135.       this.tagMap.put(Tag.MAP, new HTMLDocument.HTMLReader.MapAction(this));
  136.       this.tagMap.put(Tag.MENU, var8);
  137.       this.tagMap.put(Tag.META, new HTMLDocument.HTMLReader.MetaAction(this));
  138.       this.tagMap.put(Tag.NOFRAMES, var8);
  139.       this.tagMap.put(Tag.OBJECT, var11);
  140.       this.tagMap.put(Tag.OL, var8);
  141.       this.tagMap.put(Tag.OPTION, var12);
  142.       this.tagMap.put(Tag.P, var9);
  143.       this.tagMap.put(Tag.PARAM, new HTMLDocument.HTMLReader.ObjectAction(this));
  144.       this.tagMap.put(Tag.PRE, new HTMLDocument.HTMLReader.PreAction(this));
  145.       this.tagMap.put(Tag.SAMP, var10);
  146.       this.tagMap.put(Tag.SCRIPT, var13);
  147.       this.tagMap.put(Tag.SELECT, var12);
  148.       this.tagMap.put(Tag.SMALL, var10);
  149.       this.tagMap.put(Tag.STRIKE, var14);
  150.       this.tagMap.put(Tag.S, var10);
  151.       this.tagMap.put(Tag.STRONG, var10);
  152.       this.tagMap.put(Tag.STYLE, new HTMLDocument.HTMLReader.StyleAction(this));
  153.       this.tagMap.put(Tag.SUB, var14);
  154.       this.tagMap.put(Tag.SUP, var14);
  155.       this.tagMap.put(Tag.TABLE, var8);
  156.       this.tagMap.put(Tag.TD, var8);
  157.       this.tagMap.put(Tag.TEXTAREA, var12);
  158.       this.tagMap.put(Tag.TH, var8);
  159.       this.tagMap.put(Tag.TITLE, new HTMLDocument.HTMLReader.TitleAction(this));
  160.       this.tagMap.put(Tag.TR, var8);
  161.       this.tagMap.put(Tag.TT, var10);
  162.       this.tagMap.put(Tag.U, var14);
  163.       this.tagMap.put(Tag.UL, var8);
  164.       this.tagMap.put(Tag.VAR, var10);
  165.       this.tagMap.put(HTMLDocument.EndOfLineTag, new HTMLDocument.HTMLReader.EndOfLineAction(this));
  166.       ((AbstractDocument)var1).putProperty("AdditionalComments", (Object)null);
  167.       if (var5 != null) {
  168.          this.insertTag = var5;
  169.          this.popDepth = var3;
  170.          this.pushDepth = var4;
  171.          this.insertInsertTag = var6;
  172.          this.foundInsertTag = false;
  173.       } else {
  174.          this.foundInsertTag = true;
  175.       }
  176.  
  177.       this.midInsert = !this.emptyDocument && var5 == null;
  178.       if (this.midInsert) {
  179.          this.generateEndsSpecsForMidInsert();
  180.       }
  181.  
  182.    }
  183.  
  184.    // $FF: synthetic method
  185.    static HTMLDocument access$0(HTMLDocument$HTMLReader var0) {
  186.       return var0.this$0;
  187.    }
  188.  
  189.    void addCSSRules(String var1) {
  190.       StyleSheet var2 = this.this$0.getStyleSheet();
  191.       var2.addRule(var1);
  192.    }
  193.  
  194.    protected void addContent(char[] var1, int var2, int var3) {
  195.       this.addContent(var1, var2, var3, true);
  196.    }
  197.  
  198.    protected void addContent(char[] var1, int var2, int var3, boolean var4) {
  199.       if (this.foundInsertTag) {
  200.          if (var4 && !this.inParagraph && !this.inPre) {
  201.             this.blockOpen(Tag.IMPLIED, new SimpleAttributeSet());
  202.             this.inParagraph = true;
  203.             this.impliedP = true;
  204.          }
  205.  
  206.          this.emptyAnchor = false;
  207.          this.charAttr.addAttribute(StyleConstants.NameAttribute, Tag.CONTENT);
  208.          AttributeSet var5 = this.charAttr.copyAttributes();
  209.          DefaultStyledDocument.ElementSpec var6 = new DefaultStyledDocument.ElementSpec(var5, (short)3, var1, var2, var3);
  210.          this.parseBuffer.addElement(var6);
  211.          if (this.parseBuffer.size() > this.threshold) {
  212.             try {
  213.                this.flushBuffer();
  214.             } catch (BadLocationException var7) {
  215.             }
  216.          }
  217.  
  218.          if (var3 > 0) {
  219.             this.lastWasNewline = var1[var2 + var3 - 1] == '\n';
  220.          }
  221.  
  222.       }
  223.    }
  224.  
  225.    protected void addSpecialElement(HTML.Tag var1, MutableAttributeSet var2) {
  226.       if (var1 != Tag.FRAME && !this.inParagraph && !this.inPre) {
  227.          this.blockOpen(Tag.IMPLIED, new SimpleAttributeSet());
  228.          this.inParagraph = true;
  229.          this.impliedP = true;
  230.       }
  231.  
  232.       if (!this.foundInsertTag) {
  233.          if (!this.isInsertTag(var1)) {
  234.             return;
  235.          }
  236.  
  237.          this.foundInsertTag();
  238.          if (!this.insertInsertTag) {
  239.             return;
  240.          }
  241.       }
  242.  
  243.       this.emptyAnchor = false;
  244.       var2.addAttributes(this.charAttr);
  245.       var2.addAttribute(StyleConstants.NameAttribute, var1);
  246.       char[] var3 = new char[]{' '};
  247.       DefaultStyledDocument.ElementSpec var4 = new DefaultStyledDocument.ElementSpec(var2.copyAttributes(), (short)3, var3, 0, 1);
  248.       this.parseBuffer.addElement(var4);
  249.       if (var1 == Tag.FRAME) {
  250.          this.lastWasNewline = true;
  251.       }
  252.  
  253.    }
  254.  
  255.    private void adjustEndElement() {
  256.       int var1 = this.this$0.getLength();
  257.       if (var1 != 0) {
  258.          this.this$0.obtainLock();
  259.  
  260.          try {
  261.             Element[] var4 = this.getPathTo(var1 - 1);
  262.             if (var4.length > 2 && var4[1].getAttributes().getAttribute(StyleConstants.NameAttribute) == Tag.BODY && var4[1].getEndOffset() == var1) {
  263.                String var5 = this.this$0.getText(var1 - 1, 1);
  264.                Element[] var7 = new Element[0];
  265.                Element[] var8 = new Element[1];
  266.                int var9 = var4[0].getElementIndex(var1);
  267.                var8[0] = var4[0].getElement(var9);
  268.                ((AbstractDocument.BranchElement)var4[0]).replace(var9, 1, var7);
  269.                AbstractDocument.ElementEdit var10 = new AbstractDocument.ElementEdit(var4[0], var9, var8, var7);
  270.                AbstractDocument.DefaultDocumentEvent var6;
  271.                if (var4.length == 3 && var4[2].getAttributes().getAttribute(StyleConstants.NameAttribute) == Tag.P && !var5.equals("\n")) {
  272.                   var9 = var4[2].getElementIndex(var1 - 1);
  273.                   AttributeSet var27 = var4[2].getElement(var9).getAttributes();
  274.                   if (var27.getAttributeCount() == 1 && var27.getAttribute(StyleConstants.NameAttribute) == Tag.CONTENT) {
  275.                      var7 = new Element[1];
  276.                      var8 = new Element[]{var4[2].getElement(var9)};
  277.                      int var29 = var8[0].getStartOffset();
  278.                      var7[0] = this.this$0.createLeafElement(var4[2], var27, var29, var1 + 1);
  279.                      ((AbstractDocument.BranchElement)var4[2]).replace(var9, 1, var7);
  280.                      HTMLDocument var31 = this.this$0;
  281.                      var31.getClass();
  282.                      var6 = new AbstractDocument.DefaultDocumentEvent(var31, var29, var1 - var29 + 1, EventType.CHANGE);
  283.                      var6.addEdit(new AbstractDocument.ElementEdit(var4[2], var9, var8, var7));
  284.                   } else {
  285.                      SimpleAttributeSet var28 = new SimpleAttributeSet();
  286.                      var28.addAttribute(StyleConstants.NameAttribute, Tag.CONTENT);
  287.                      var7 = new Element[]{this.this$0.createLeafElement(var4[2], var28, var1, var1 + 1)};
  288.                      ((AbstractDocument.BranchElement)var4[2]).replace(var9 + 1, 0, var7);
  289.                      HTMLDocument var30 = this.this$0;
  290.                      var30.getClass();
  291.                      var6 = new AbstractDocument.DefaultDocumentEvent(var30, var1, 1, EventType.CHANGE);
  292.                      var8 = new Element[0];
  293.                      var6.addEdit(new AbstractDocument.ElementEdit(var4[2], var9 + 1, var8, var7));
  294.                   }
  295.                } else {
  296.                   SimpleAttributeSet var11 = new SimpleAttributeSet();
  297.                   var11.addAttribute(StyleConstants.NameAttribute, Tag.P);
  298.                   AbstractDocument.BranchElement var12 = (AbstractDocument.BranchElement)this.this$0.createBranchElement(var4[1], var11);
  299.                   var7 = new Element[]{var12};
  300.                   var8 = new Element[0];
  301.                   var9 = var4[1].getElementIndex(var1 - 1) + 1;
  302.                   ((AbstractDocument.BranchElement)var4[1]).replace(var9, 0, var7);
  303.                   HTMLDocument var10002 = this.this$0;
  304.                   var10002.getClass();
  305.                   var6 = new AbstractDocument.DefaultDocumentEvent(var10002, var1, 1, EventType.CHANGE);
  306.                   var6.addEdit(new AbstractDocument.ElementEdit(var4[1], var9, var8, var7));
  307.                   var7 = new Element[1];
  308.                   var11 = new SimpleAttributeSet();
  309.                   var11.addAttribute(StyleConstants.NameAttribute, Tag.CONTENT);
  310.                   var7[0] = this.this$0.createLeafElement(var12, var11, var1, var1 + 1);
  311.                   var12.replace(0, 0, var7);
  312.                }
  313.  
  314.                var6.addEdit(var10);
  315.                ((CompoundEdit)var6).end();
  316.                this.this$0.fireChangedUpdate(var6);
  317.                this.this$0.fireUndoableEditUpdate(new UndoableEditEvent(this, var6));
  318.             }
  319.          } catch (BadLocationException var15) {
  320.          } finally {
  321.             this.this$0.releaseLock();
  322.          }
  323.  
  324.       }
  325.    }
  326.  
  327.    protected void blockClose(HTML.Tag var1) {
  328.       if (this.foundInsertTag) {
  329.          if (!this.lastWasNewline) {
  330.             this.addContent(HTMLDocument.access$0(), 0, 1, this.insertTag != null);
  331.             this.lastWasNewline = true;
  332.          }
  333.  
  334.          if (this.impliedP) {
  335.             this.impliedP = false;
  336.             this.inParagraph = false;
  337.             this.blockClose(Tag.IMPLIED);
  338.          }
  339.  
  340.          --this.inBlock;
  341.          DefaultStyledDocument.ElementSpec var2 = this.parseBuffer.size() > 0 ? (DefaultStyledDocument.ElementSpec)this.parseBuffer.lastElement() : null;
  342.          if (var2 != null && var2.getType() == 1) {
  343.             char[] var3 = new char[]{' '};
  344.             this.addContent(var3, 0, 1);
  345.          }
  346.  
  347.          DefaultStyledDocument.ElementSpec var4 = new DefaultStyledDocument.ElementSpec((AttributeSet)null, (short)2);
  348.          this.parseBuffer.addElement(var4);
  349.       }
  350.    }
  351.  
  352.    protected void blockOpen(HTML.Tag var1, MutableAttributeSet var2) {
  353.       if (this.impliedP) {
  354.          this.impliedP = false;
  355.          this.inParagraph = false;
  356.          this.blockClose(Tag.IMPLIED);
  357.       }
  358.  
  359.       ++this.inBlock;
  360.       if (!this.foundInsertTag) {
  361.          if (!this.isInsertTag(var1)) {
  362.             return;
  363.          }
  364.  
  365.          this.foundInsertTag();
  366.          if (!this.insertInsertTag) {
  367.             return;
  368.          }
  369.       }
  370.  
  371.       this.lastWasNewline = false;
  372.       var2.addAttribute(StyleConstants.NameAttribute, var1);
  373.       DefaultStyledDocument.ElementSpec var3 = new DefaultStyledDocument.ElementSpec(var2.copyAttributes(), (short)1);
  374.       this.parseBuffer.addElement(var3);
  375.    }
  376.  
  377.    private int depthTo(int var1) {
  378.       Element var2 = this.this$0.getDefaultRootElement();
  379.  
  380.       int var3;
  381.       for(var3 = 0; !var2.isLeaf(); var2 = var2.getElement(var2.getElementIndex(var1))) {
  382.          ++var3;
  383.       }
  384.  
  385.       return var3;
  386.    }
  387.  
  388.    public void flush() throws BadLocationException {
  389.       this.flushBuffer();
  390.       if (this.emptyDocument) {
  391.          this.adjustEndElement();
  392.       }
  393.  
  394.    }
  395.  
  396.    void flushBuffer() throws BadLocationException {
  397.       int var1 = this.this$0.getLength();
  398.       DefaultStyledDocument.ElementSpec[] var2 = new DefaultStyledDocument.ElementSpec[this.parseBuffer.size()];
  399.       this.parseBuffer.copyInto(var2);
  400.       if (var1 == 0 && this.insertTag == null) {
  401.          this.this$0.create(var2);
  402.       } else {
  403.          this.this$0.insert(this.offset, var2);
  404.       }
  405.  
  406.       this.parseBuffer.removeAllElements();
  407.       this.offset += this.this$0.getLength() - var1;
  408.    }
  409.  
  410.    private void foundInsertTag() {
  411.       this.foundInsertTag = true;
  412.       if (this.popDepth > 0 || this.pushDepth > 0) {
  413.          try {
  414.             if (this.offset == 0 || !this.this$0.getText(this.offset - 1, 1).equals("\n")) {
  415.                SimpleAttributeSet var1 = null;
  416.                boolean var2 = true;
  417.                if (this.offset != 0) {
  418.                   Element var3 = this.this$0.getCharacterElement(this.offset - 1);
  419.                   AttributeSet var4 = var3.getAttributes();
  420.                   if (var4.isDefined(StyleConstants.ComposedTextAttribute)) {
  421.                      var2 = false;
  422.                   } else {
  423.                      Object var5 = var4.getAttribute(StyleConstants.NameAttribute);
  424.                      if (var5 instanceof HTML.Tag) {
  425.                         HTML.Tag var6 = (HTML.Tag)var5;
  426.                         if (var6 == Tag.IMG || var6 == Tag.HR || var6 == Tag.COMMENT || var6 instanceof HTML.UnknownTag) {
  427.                            var2 = false;
  428.                         }
  429.                      }
  430.                   }
  431.                }
  432.  
  433.                if (!var2) {
  434.                   var1 = new SimpleAttributeSet();
  435.                   ((SimpleAttributeSet)var1).addAttribute(StyleConstants.NameAttribute, Tag.CONTENT);
  436.                }
  437.  
  438.                DefaultStyledDocument.ElementSpec var10 = new DefaultStyledDocument.ElementSpec(var1, (short)3, HTMLDocument.access$0(), 0, HTMLDocument.access$0().length);
  439.                if (var2) {
  440.                   var10.setDirection((short)4);
  441.                }
  442.  
  443.                this.parseBuffer.addElement(var10);
  444.             }
  445.          } catch (BadLocationException var7) {
  446.          }
  447.       }
  448.  
  449.       for(int var8 = 0; var8 < this.popDepth; ++var8) {
  450.          this.parseBuffer.addElement(new DefaultStyledDocument.ElementSpec((AttributeSet)null, (short)2));
  451.       }
  452.  
  453.       for(int var9 = 0; var9 < this.pushDepth; ++var9) {
  454.          DefaultStyledDocument.ElementSpec var11 = new DefaultStyledDocument.ElementSpec((AttributeSet)null, (short)1);
  455.          var11.setDirection((short)5);
  456.          this.parseBuffer.addElement(var11);
  457.       }
  458.  
  459.    }
  460.  
  461.    private void generateEndsSpecsForMidInsert() {
  462.       int var1 = this.heightToElementWithName(Tag.BODY, Math.max(0, this.offset - 1));
  463.       boolean var2 = false;
  464.       if (var1 == -1 && this.offset > 0) {
  465.          var1 = this.heightToElementWithName(Tag.BODY, this.offset);
  466.          if (var1 != -1) {
  467.             var1 = this.depthTo(this.offset - 1) - 1;
  468.             var2 = true;
  469.          }
  470.       }
  471.  
  472.       if (var1 == -1) {
  473.          throw new RuntimeException("Must insert new content into body element-");
  474.       } else {
  475.          if (var1 != -1) {
  476.             try {
  477.                if (!var2 && this.offset > 0 && !this.this$0.getText(this.offset - 1, 1).equals("\n")) {
  478.                   SimpleAttributeSet var3 = new SimpleAttributeSet();
  479.                   var3.addAttribute(StyleConstants.NameAttribute, Tag.CONTENT);
  480.                   DefaultStyledDocument.ElementSpec var4 = new DefaultStyledDocument.ElementSpec(var3, (short)3, HTMLDocument.access$0(), 0, 1);
  481.                   this.parseBuffer.addElement(var4);
  482.                }
  483.             } catch (BadLocationException var5) {
  484.             }
  485.  
  486.             while(var1-- > 0) {
  487.                this.parseBuffer.addElement(new DefaultStyledDocument.ElementSpec((AttributeSet)null, (short)2));
  488.             }
  489.  
  490.             if (var2) {
  491.                DefaultStyledDocument.ElementSpec var6 = new DefaultStyledDocument.ElementSpec((AttributeSet)null, (short)1);
  492.                var6.setDirection((short)5);
  493.                this.parseBuffer.addElement(var6);
  494.             }
  495.          }
  496.  
  497.       }
  498.    }
  499.  
  500.    private Element[] getPathTo(int var1) {
  501.       Stack var2 = new Stack();
  502.  
  503.       for(Element var3 = this.this$0.getDefaultRootElement(); !var3.isLeaf(); var3 = var3.getElement(var3.getElementIndex(var1))) {
  504.          var2.push(var3);
  505.       }
  506.  
  507.       Element[] var5 = new Element[((Vector)var2).size()];
  508.       ((Vector)var2).copyInto(var5);
  509.       return var5;
  510.    }
  511.  
  512.    public void handleComment(char[] var1, int var2) {
  513.       if (this.inStyle) {
  514.          if (this.styles != null) {
  515.             this.styles.addElement(new String(var1));
  516.          }
  517.       } else if (this.this$0.getPreservesUnknownTags()) {
  518.          if (this.inBlock == 0) {
  519.             Object var4 = this.this$0.getProperty("AdditionalComments");
  520.             if (var4 != null && !(var4 instanceof Vector)) {
  521.                return;
  522.             }
  523.  
  524.             if (var4 == null) {
  525.                var4 = new Vector();
  526.                this.this$0.putProperty("AdditionalComments", var4);
  527.             }
  528.  
  529.             ((Vector)var4).addElement(new String(var1));
  530.             return;
  531.          }
  532.  
  533.          SimpleAttributeSet var3 = new SimpleAttributeSet();
  534.          var3.addAttribute(Attribute.COMMENT, new String(var1));
  535.          this.addSpecialElement(Tag.COMMENT, var3);
  536.       }
  537.  
  538.    }
  539.  
  540.    public void handleEndTag(HTML.Tag var1, int var2) {
  541.       if (!this.midInsert || this.inBody) {
  542.          if (var1 == Tag.BODY) {
  543.             this.inBody = false;
  544.             if (this.midInsert) {
  545.                --this.inBlock;
  546.             }
  547.          }
  548.  
  549.          HTMLDocument.HTMLReader.TagAction var3 = (HTMLDocument.HTMLReader.TagAction)this.tagMap.get(var1);
  550.          if (var3 != null) {
  551.             var3.end(var1);
  552.          }
  553.  
  554.       }
  555.    }
  556.  
  557.    public void handleSimpleTag(HTML.Tag var1, MutableAttributeSet var2, int var3) {
  558.       if (!this.midInsert || this.inBody) {
  559.          if (this.isStyleCSS && var2.isDefined(Attribute.STYLE)) {
  560.             String var4 = (String)var2.getAttribute(Attribute.STYLE);
  561.             var2.removeAttribute(Attribute.STYLE);
  562.             this.styleAttributes = this.this$0.getStyleSheet().getDeclaration(var4);
  563.             var2.addAttributes(this.styleAttributes);
  564.          } else {
  565.             this.styleAttributes = null;
  566.          }
  567.  
  568.          HTMLDocument.HTMLReader.TagAction var5 = (HTMLDocument.HTMLReader.TagAction)this.tagMap.get(var1);
  569.          if (var5 != null) {
  570.             var5.start(var1, var2);
  571.             var5.end(var1);
  572.          } else if (this.this$0.getPreservesUnknownTags()) {
  573.             this.addSpecialElement(var1, var2);
  574.          }
  575.  
  576.       }
  577.    }
  578.  
  579.    public void handleStartTag(HTML.Tag var1, MutableAttributeSet var2, int var3) {
  580.       if (this.midInsert && !this.inBody) {
  581.          if (var1 == Tag.BODY) {
  582.             this.inBody = true;
  583.             ++this.inBlock;
  584.          }
  585.  
  586.       } else {
  587.          if (!this.inBody && var1 == Tag.BODY) {
  588.             this.inBody = true;
  589.          }
  590.  
  591.          if (this.isStyleCSS && var2.isDefined(Attribute.STYLE)) {
  592.             String var4 = (String)var2.getAttribute(Attribute.STYLE);
  593.             var2.removeAttribute(Attribute.STYLE);
  594.             this.styleAttributes = this.this$0.getStyleSheet().getDeclaration(var4);
  595.             var2.addAttributes(this.styleAttributes);
  596.          } else {
  597.             this.styleAttributes = null;
  598.          }
  599.  
  600.          HTMLDocument.HTMLReader.TagAction var5 = (HTMLDocument.HTMLReader.TagAction)this.tagMap.get(var1);
  601.          if (var5 != null) {
  602.             var5.start(var1, var2);
  603.          }
  604.  
  605.       }
  606.    }
  607.  
  608.    public void handleText(char[] var1, int var2) {
  609.       if (!this.midInsert || this.inBody) {
  610.          if (this.inTextArea) {
  611.             this.textAreaContent(var1);
  612.          } else if (this.inPre) {
  613.             this.preContent(var1);
  614.          } else if (this.inTitle) {
  615.             this.this$0.putProperty("title", new String(var1));
  616.          } else if (this.option != null) {
  617.             this.option.setLabel(new String(var1));
  618.          } else if (this.inStyle) {
  619.             if (this.styles != null) {
  620.                this.styles.addElement(new String(var1));
  621.             }
  622.          } else if (this.inBlock > 0 && var1.length >= 1) {
  623.             this.addContent(var1, 0, var1.length);
  624.          }
  625.  
  626.       }
  627.    }
  628.  
  629.    private int heightToElementWithName(Object var1, int var2) {
  630.       Element var3 = this.this$0.getCharacterElement(var2).getParentElement();
  631.  
  632.       int var4;
  633.       for(var4 = 0; var3 != null && var3.getAttributes().getAttribute(StyleConstants.NameAttribute) != var1; var3 = var3.getParentElement()) {
  634.          ++var4;
  635.       }
  636.  
  637.       return var3 == null ? -1 : var4;
  638.    }
  639.  
  640.    private boolean isInsertTag(HTML.Tag var1) {
  641.       return this.insertTag == var1 || var1 == Tag.IMPLIED && var1 == Tag.P;
  642.    }
  643.  
  644.    void linkCSSStyleSheet(String var1) {
  645.       Object var2 = null;
  646.  
  647.       try {
  648.          var5 = new URL(this.this$0.base, var1);
  649.       } catch (MalformedURLException var4) {
  650.          try {
  651.             var5 = new URL(var1);
  652.          } catch (MalformedURLException var3) {
  653.             var5 = null;
  654.          }
  655.       }
  656.  
  657.       if (var5 != null) {
  658.          this.this$0.getStyleSheet().importStyleSheet(var5);
  659.       }
  660.  
  661.    }
  662.  
  663.    protected void popCharacterStyle() {
  664.       if (!this.charAttrStack.empty()) {
  665.          this.charAttr = (MutableAttributeSet)this.charAttrStack.peek();
  666.          this.charAttrStack.pop();
  667.       }
  668.  
  669.    }
  670.  
  671.    protected void preContent(char[] var1) {
  672.       int var2 = 0;
  673.  
  674.       for(int var3 = 0; var3 < var1.length; ++var3) {
  675.          if (var1[var3] == '\n') {
  676.             this.addContent(var1, var2, var3 - var2 + 1);
  677.             this.blockClose(Tag.IMPLIED);
  678.             SimpleAttributeSet var4 = new SimpleAttributeSet();
  679.             var4.addAttribute(javax.swing.text.html.CSS.Attribute.WHITE_SPACE, "pre");
  680.             this.blockOpen(Tag.IMPLIED, var4);
  681.             var2 = var3 + 1;
  682.          }
  683.       }
  684.  
  685.       if (var2 < var1.length) {
  686.          this.addContent(var1, var2, var1.length - var2);
  687.       }
  688.  
  689.    }
  690.  
  691.    protected void pushCharacterStyle() {
  692.       this.charAttrStack.push(this.charAttr.copyAttributes());
  693.    }
  694.  
  695.    protected void registerTag(HTML.Tag var1, HTMLDocument.HTMLReader.TagAction var2) {
  696.       this.tagMap.put(var1, var2);
  697.    }
  698.  
  699.    protected void textAreaContent(char[] var1) {
  700.       try {
  701.          this.textAreaDocument.insertString(this.textAreaDocument.getLength(), new String(var1), (AttributeSet)null);
  702.       } catch (BadLocationException var2) {
  703.       }
  704.  
  705.    }
  706. }
  707.